package com.yf.controller.admin.course;

import java.util.List;
import java.util.Map;

import com.yf.entity.course.TopCourseEntity;
import com.yf.service.course.TopCourseService;
import com.yf.vo.LessonRecordBackVo;
import com.yf.vo.TopCourseBackVo;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yf.annotation.SysLog;
import com.yf.response.R;
import com.yf.consts.DaoConst;


/**
 * 推荐课程Controller
 *
 * @author hxf
 * @email 505860922@qq.com
 * @date Wed Oct 31 09:51:28 CST 2018
 */
@RestController
@RequestMapping("/topcourse")
public class TopCourseController {
    @Autowired
    private TopCourseService topCourseService;

    /**
     * 列表推荐课程
     */
    @RequestMapping("/list")
    @RequiresPermissions("topcourse:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params),DaoConst.getLIMIT(params));
        List<TopCourseEntity> topCourseList = topCourseService.queryList(params);
        return R.ok(new PageInfo(topCourseList));
    }

    /**
     * 查看推荐课程
     */
    @SysLog("查看推荐课程")
    @RequestMapping("/info/{id}")
    @RequiresPermissions("topcourse:info")
    public R info(@PathVariable("id") Long id) {
        TopCourseEntity topCourse = topCourseService.get(id);

        return R.ok(topCourse);
    }

    /**
     * 保存推荐课程
     */
    @SysLog("保存推荐课程")
    @RequestMapping("/save")
    @RequiresPermissions("topcourse:save")
    public R save(TopCourseEntity topCourse) {
        topCourseService.save(topCourse);

        return R.ok(topCourse);
    }

    /**
     * 修改推荐课程
     */
    @SysLog("修改推荐课程")
    @RequestMapping("/update")
    @RequiresPermissions("topcourse:update")
    public R update(TopCourseEntity topCourse) {
        topCourseService.update(topCourse);

        return R.ok(topCourse);
    }

    /**
     * 删除推荐课程
     */
    @SysLog("删除推荐课程")
    @RequestMapping("/delete")
    @RequiresPermissions("topcourse:delete")
    public R delete(@RequestBody Long[]ids) {
        topCourseService.deleteBatch(ids);

        return R.ok();
    }

    /**
     * 所有推荐课程
     */
    @SysLog("所有推荐课程")
    @RequestMapping("/queryAll")
    public R queryAll(@RequestParam Map<String, Object> params) {

        List<TopCourseEntity> topCourseList = topCourseService.queryList(params);

        return R.ok(topCourseList);
    }

    /***********自定义开始***********/

    /**
     * back 推荐课程
     * @return
     */
    @RequestMapping("/topCourseList")
    public R getCampaignVoList(@RequestParam Map<String, Object> params) {
        PageHelper.startPage(DaoConst.getPage(params), DaoConst.getLIMIT(params));
        List<TopCourseBackVo> list = topCourseService.topCourseList(params);
        return R.ok(new PageInfo(list));

    }

}
